<!DOCTYPE html>
<html>
	{include file="public1/_header" /}
	
	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>年级考勤</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="float:right" onclick="location.reload()" title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
			</a>
		</div>
		
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body">
							<blockquote class="layui-elem-quote layui-quote-nm">
								<form class="layui-form layui-col-space5" onsubmit="return false;">
									<div class="layui-input-inline layui-show-xs-block">
										<select name="class_id" id="class_id" lay-verify="required" lay-reqText="班级必须填写" lay-search="">
											<option value="">直接选择或搜索班级</option>
											{foreach $class_arr as $key=>$vo }
											<option value="{$vo.id}">{$vo.name}</option>
											{/foreach}

										</select>
									</div>
									<div class="layui-input-inline layui-show-xs-block">
										<button class="layui-btn" lay-submit="" lay-filter="sreach">查询</button>
										<button class="layui-btn  layui-btn-primary" onclick="location.reload();return false;">重置</button>
									</div>
								</form>
							</blockquote>
							<table class="layui-hide" id="test" lay-filter="test"></table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
					<!--<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">-->
						<!--<i class="layui-icon">&#xe642;</i>删除-->
					<!--</button>-->
				</div>
		</script>

		<script type="text/javascript">
			var url = "__STATIC__/admin/"
			layui.extend({
				notice: 'notice/notice'
			}).use(['util', 'laydate', 'table','form','notice'], function() {
				var table = layui.table;
				var form = layui.form;
				var util = layui.util;
				var notice = layui.notice;
				var tableIns = table.render({
					id: 'testReload',
					elem: '#test',
					url: "{:url('lists')}",
					method: "POST",
					request: {
						pageName: 'offset', //页码的参数名称，默认：page
						limitName: 'limit' //每页数据量的参数名，默认：limit
					},
					where: {
						grade_id:"{$Request.get.id}",
						event_id:"{$Request.get.event_id}",
					},
					toolbar: '#toolbarDemo',
					cols: [
						[/*{
							type: 'checkbox',
							fixed: 'left',
							width: 80
						},*/ {
							field: 'class_name',
							title: "班级",

						}, {
							field: 'student_number',
							title: "学号",

						}, {
							field: 'student_name',
							title: "姓名",

						} , {
							field: 'att_time',
							title: "打卡时间",
							templet: function(d) {
								var logoSrc = util.toDateString(d.att_time * 1000, "yyyy-MM-dd HH:mm:ss");
								return logoSrc;
							},
							sort: true
						},{
							field: 'status',
							title: "考勤状态"
						}, {
							field: 'classroom_name',
							title: "打卡地点",

						}]
					],
					page: true
				});

				//头工具栏事件
				table.on('toolbar(test)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case 'getCheckLength':
							var data = checkStatus.data;

							if (data.length < 1) {
								layer.msg('您最少选择一个选项进行操作');
								return false;
							}
							var ids = [];
							data.forEach(function(item, index) {
								ids.push(item.id)
							})
							parent.layer.confirm('确认要删除这些内容？', function() {
								$.post("{:url('gradedelete')}", {
									ids: ids,
									user_id: "{$Think.session.admin.id}"
								}, function(res) {
									if (res.status == 1) {
										parent.layer.msg('删除成功', {
											icon: 1,
											time: 300
										}, function() {
											tableIns.reload()
										});
									} else {
										parent.layer.msg(res.message)
									}
								})
							});

							break;
					};
				});


				//搜索
				form.on('submit(sreach)', function(data) {
					//执行重载
					table.reload('testReload', {
							method: "POST",
							request: {
								pageName: 'offset', //页码的参数名称，默认：page
								limitName: 'limit' //每页数据量的参数名，默认：limit
							},
							where: {
								s_or_c_id: 1,
								is_school_msg: 1,
								grade_id: data.field.grade_id,
								keywords:data.field.class_id,
							},
					        page: {
					          curr: 1 //重新从第 1 页开始
					        }
					});
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});

			});
			
		</script>
	</body>
</html>
